import { createHashRouter } from 'react-router-dom'
// import MainLayout from '../components/layout/MainLayout'
import Home from '../pages/Home'
import AICompanionDetail from '../pages/AICompanionDetail'
import AICompanionList from '../pages/AICompanionList'
import AIChat from '../pages/AIChat'
import AIPhotoAlbum from '../pages/AIPhotoAlbum'
import VideoPlayer from '../pages/VideoPlayer'
import Discover from '../pages/Discover'
import ASMR from '../pages/ASMR'
import Profile from '../pages/Profile'
import Settings from '../pages/Settings'
import Help from '../pages/Help'
import History from '../pages/History'
import Prototype from '../pages/Prototype'
import PremiumContent from '../pages/PremiumContent'

// 全局路由变化后的滚动重置逻辑
export const scrollReset = () => {
  // 确保在路由变化后重置body的overflow样式
  document.body.style.removeProperty('overflow');
  document.documentElement.style.overflowY = 'auto';
  document.body.style.overflowY = 'auto';
  
  // 重置滚动位置
  window.scrollTo(0, 0);
};

const router = createHashRouter([
  {
    path: '/',
    element: <Home />,
  },
  {
    path: '/ai-companion/:id',
    element: <AICompanionDetail />,
  },
  {
    path: '/ai-companion',
    element: <AICompanionList />,
  },
  {
    path: '/ai-companion/:id/chat',
    element: <AIChat />,
  },
  {
    path: '/AIPhotoAlbum/:id/album',
    element: <AIPhotoAlbum />,
  },
  {
    path: '/video/:id',
    element: <VideoPlayer />,
  },
  {
    path: '/discover',
    element: <Discover />,
  },
  {
    path: '/asmr',
    element: <ASMR />,
  },
  {
    path: '/profile',
    element: <Profile />,
  },
  {
    path: '/history',
    element: <History />,
  },
  {
    path: '/settings',
    element: <Settings />,
  },
  {
    path: '/help',
    element: <Help />,
  },
  {
    path: '/prototype',
    element: <Prototype />,
  },
  {
    path: '/premium/:id',
    element: <PremiumContent />,
  },
  {
    path: '*',
    element: <Home />, // 使用Home页面作为默认的404页面处理
  },
], {
  future: {
    v7_relativeSplatPath: true,
  }
})

// 添加路由切换后的重置滚动逻辑
window.addEventListener('popstate', () => {
  // 在浏览器历史导航后调用滚动重置
  setTimeout(scrollReset, 100);
});

export default router 